package com.dc.cameraxtest.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.dc.cameraxtest.R

/**
 * @projectName uv
 * @description:
 * @author dc
 * @date :2025.2.24 11:01
 */
class PagesAdapter(private val items: List<String>,  private val itemClickListener: OnItemClickListener) : RecyclerView.Adapter<PagesAdapter.ViewHolder>() {
    class ViewHolder(itemView: View, private val listener: OnItemClickListener) : RecyclerView.ViewHolder(itemView) {
        val textView: TextView = itemView.findViewById(R.id.textView)

        init {
            // 为项设置点击事件监听器
            itemView.setOnClickListener {
                listener.onItemClick(adapterPosition)
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_home, parent, false)
        return ViewHolder(itemView , itemClickListener)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.textView.text = items[position]
    }

    override fun getItemCount(): Int = items.size


    // 定义点击事件监听器接口
    interface OnItemClickListener {
        fun onItemClick(position: Int)
    }
}